﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;


public class LoginScreen : Networking {

    private string name = "";
    float updateUI = 25.0f;
	float timer = 0; 	
	Vector2 _slightPadding = new Vector2(Screen.width * 0.025f,Screen.height * 0.05f); 	
	Rect _area; 	
	Rect leftArea, middleArea, RightArea; 
	int amountOfScoresToGet = 10;
	string username;
	// Use this for initialization
	void Start () {
		base.Start ();
		getScores (0,amountOfScoresToGet);
		username = PlayerPrefs.GetString ("username");
	}
	public void OnGUI() 
	{  	
		base.OnGUI ();	
			_area = new Rect(0,0 , Screen.width, Screen.height);
			leftArea = new Rect(_slightPadding.x,_slightPadding.y,_area.width * 0.3f,_area.height * 0.9f);
			
			middleArea = new Rect(_area.width*0.33f + _slightPadding.x,_slightPadding.y,_area.width * 0.3f,_area.height * 0.9f);	
			RightArea = new Rect(_area.width*0.66f + _slightPadding.x,_slightPadding.y,_area.width * 0.3f,_area.height * 0.9f);	
			GUI.BeginGroup(new Rect(0,0,Screen.width,Screen.height)); 	
			GUI.Box(_area,"",backgroundStyle);	
			GUI.BeginGroup(leftArea); 		
			GUI.Box(new Rect(0,0,leftArea.width,leftArea.height*0.25f),"Store", UIBox); 
			GUI.Box(new Rect(0,leftArea.height*0.25f,leftArea.width,leftArea.height * 0.75f), "Leaderboard",UIBox); 	
			LeaderBoard(new Rect(0,leftArea.height*0.38f,leftArea.width,leftArea.height * 0.675f),amountOfScoresToGet); 	
			GUI.EndGroup(); 	
			GUI.BeginGroup(middleArea);
			GUI.Box(new Rect(0,0,middleArea.width,middleArea.height*0.25f),"Number Knight", UIBox); 	
			MenuButtons(new Rect(0,middleArea.height*0.25f,middleArea.width,middleArea.height*0.75f)); 	
			GUI.EndGroup(); 	
			GUI.BeginGroup(RightArea);
			AccountArea (new Rect (0, 0, RightArea.width, RightArea.height * 0.25f));
			GUI.Box(new Rect(0,RightArea.height*0.25f,RightArea.width,RightArea.height * 0.75f), "News", UIBox); 		
			GUI.EndGroup(); 		
			GUI.EndGroup();  
		} 	
		void MenuButtons(Rect area) 
		{ 		int numOfButtons = 4; 	
			if (GUI.Button (new Rect (area.x, area.y, area.width, area.height / numOfButtons), "Play", UIButton)) {
						Application.LoadLevel ("mainScene");
						PlayerPrefs.SetString ("username", username);
				}
		GUI.Button(new Rect(area.x,area.y+area.height/numOfButtons,area.width, area.height/numOfButtons),"Multiplayer",UIButton); 
		GUI.Button(new Rect(area.x,area.y+(area.height/numOfButtons)*2,area.width, area.height/numOfButtons),"Options",UIButton);
		GUI.Button(new Rect(area.x,area.y+(area.height/numOfButtons)*3,area.width, area.height/numOfButtons),"Quit",UIButton);
		}
		void AccountArea(Rect area)
		{
			int numOfItems = 1;
			/*if (!(username == "")) {
						GUI.Box (new Rect (area.x, area.y, area.width / numOfItems, area.height), "Logged in as : " + username, mySkin.box);
						GUI.Button (new Rect (area.x + area.width / numOfItems, area.y, area.width / numOfItems, area.height), "Logout", mySkin.button);
				} else {
					GUI.Button (new Rect (area.x, area.y, area.width, area.height), "Login", mySkin.button);
				}*/
			GUI.Label (new Rect (area.x, area.y, area.width * 0.25f, area.height / 4), "Username", customSkin.box);
			username  = GUI.TextArea (new Rect (area.x + (area.width * 0.3f), area.y, area.width * 0.6f, area.height / 4), username, customSkin.textArea);
		}

	void LoginWindow()
	{

	}
		

	// Update is called once per frame
	void Update () {
        timer += Time.deltaTime;
        if (timer > updateUI)
        {
            timer = 0;
        }
	}
}
